﻿using System;
using System.Threading.Tasks;

namespace oueb.mod
{
    using Ceen;
    public class OptionsModule : IHttpModule
    {
        internal string allow { get; set; }
        public OptionsModule() : this("OPTIONS, GET, HEAD, PUT, POST")
        {
        }
        public OptionsModule(string allow)
        {
            this.allow = allow;
        }
        public Task<bool> HandleAsync(IHttpContext context)
        {
            if (context.Request.Method != "OPTIONS") return Task.FromResult(false);
            context.Response.StatusCode = HttpStatusCode.NoContent;
            context.Response.AddHeader("Allow", allow);
            return Task.FromResult(true);
        }
    }
}
